package org.fujay.commons.langchain4j;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import org.fujay.commons.langchain4j.config.ModelConfig;
import org.fujay.commons.langchain4j.config.RagConfig;
import org.fujay.commons.langchain4j.server.ChatService;
import org.fujay.commons.langchain4j.server.DocumentService;
import org.fujay.commons.langchain4j.server.MultiService;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author slm
 * @description
 */
@AutoConfiguration
@Import({ModelConfig.class, RagConfig.class})
public class LangChain4jConfig {

    @Bean
    @Lazy
    public ChatService chatService(ChatMemoryStore chatMemoryStore,
                                   ThreadPoolTaskExecutor threadPoolTaskExecutor, OpenSearchClient openSearchClient, EmbeddingStore<TextSegment> embeddingStore) {
        return new ChatService(chatMemoryStore, threadPoolTaskExecutor, openSearchClient, embeddingStore);
    }

    @Bean
    public DocumentService documentService(EmbeddingStore<TextSegment> embeddingStore,
                                           OpenSearchClient openSearchClient) {
        return new DocumentService(embeddingStore, openSearchClient);
    }

    @Bean
    public MultiService multiService(ChatMemoryStore chatMemoryStore,
                                     ThreadPoolTaskExecutor threadPoolTaskExecutor) {
        return new MultiService(chatMemoryStore, threadPoolTaskExecutor);
    }
}
